<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>如果给定的函数已经被定义就返回 true</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.func-num-args.html">« func_num_args</a></li>
      <li style="float: right;"><a href="function.get-defined-functions.html">get_defined_functions »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.funchand.html">函数处理 函数</a></li>
    <li>如果给定的函数已经被定义就返回 true</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.function-exists" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">function_exists</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">function_exists</span> &mdash; <span class="dc-title">如果给定的函数已经被定义就返回 <strong><code>true</code></strong></span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.function-exists-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>function_exists</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$function</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   在已经定义的函数列表（包括系统自带的函数和用户自定义的函数）中查找 <code class="parameter">function</code>。 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.function-exists-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">function</code></dt>

     <dd>

      <p class="para">
       函数名，必须为一个字符串。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.function-exists-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果 <code class="parameter">function</code> 存在且的确是一个函数就返回 <strong><code>true</code></strong>，反之则返回 <strong><code>false</code></strong>。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    对于语法结构的判断，例如 <span class="function"><a href="function.include-once.html" class="function">include_once</a></span> 和 <span class="function"><a href="function.echo.html" class="function">echo</a></span> 将会返回 <strong><code>false</code></strong>。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 examples" id="refsect1-function.function-exists-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5088">
    <p><strong>示例 #1 <span class="function"><strong>function_exists()</strong></span> 的例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">function_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'imap_open'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"IMAP&nbsp;functions&nbsp;are&nbsp;available.&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"IMAP&nbsp;functions&nbsp;are&nbsp;not&nbsp;available.&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.function-exists-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    即使函数本身由于配置或者编译选项而无法使用，该函数名也可能存在（<a href="ref.image.html" class="link">image</a> 就是一个现成的例子）。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.function-exists-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.method-exists.html" class="function" rel="rdfs-seeAlso">method_exists()</a> - 检查类的方法是否存在</span></li>
    <li class="member"><span class="function"><a href="function.is-callable.html" class="function" rel="rdfs-seeAlso">is_callable()</a> - 验证值是否可以在当前范围内作为函数调用。</span></li>
    <li class="member"><span class="function"><a href="function.get-defined-functions.html" class="function" rel="rdfs-seeAlso">get_defined_functions()</a> - 返回所有已定义函数的数组</span></li>
    <li class="member"><span class="function"><a href="function.class-exists.html" class="function" rel="rdfs-seeAlso">class_exists()</a> - 查类是否已经定义</span></li>
    <li class="member"><span class="function"><a href="function.extension-loaded.html" class="function" rel="rdfs-seeAlso">extension_loaded()</a> - 检查一个扩展是否已经加载</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>